package com.tangruojie.optional;

import com.tangruojie.entity.Author;
import com.tangruojie.stream.StreamDemoTest;

import java.util.*;
import java.util.function.Consumer;

/**
 * 安全的消费值
 */
public class OptionalDemo02 {

    public static void main(String[] args) {

        List<Author> authors = StreamDemoTest.getAuthors();

        List<Author> authorList = new ArrayList<>();

        Optional<List<Author>> optionalAuthors = Optional.of(authors);
        optionalAuthors.ifPresent(new Consumer<List<Author>>() {
            @Override
            public void accept(List<Author> authors) {
                for (Author author : authors) {
                    if (!authorList.contains(author)) {
                        authorList.add(author);
                        System.out.println(author.getName());
                    }
                }
            }
        });

    }

}
